package strategy.promotion;

import java.util.HashMap;
import java.util.Map;

public class PromotionStrategyFactory {
    private PromotionStrategyFactory(){
    }
    //提供一个map，将所有的策略封装起来
    public static Map<String,PromotionStrategy> strategyMap=new HashMap<>();
    //静态代码块去将所有的策略对象封装，提供一个枚举得到所有的键
    static {
        strategyMap.put(PromotionKey.CASHBACK.getCode(),new CashBackStrategy());
        strategyMap.put(PromotionKey.COUPON.getCode(),new CouponStrategy());
        strategyMap.put(PromotionKey.GROUP.getCode(),new GroupByStrategy());
    }
    //无促销活动，提供一个默认的策略
    private static final PromotionStrategy NON_PROMOTION = new EmptyStrategy();

    public static PromotionStrategy getStrategy(String key){
        PromotionStrategy promotionStrategy = strategyMap.get(key);
        return promotionStrategy==null?NON_PROMOTION:promotionStrategy;

    }
}
